package com.hnit.applet.common.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author zwj
 * @date 2022/6/27
 * @description TODO
 */
@Configuration
@RefreshScope
public class DruidConfiguration {

    @Resource
    private DataSourcePropertiesConfig dataConfig;

    @Bean
    @RefreshScope
    public DruidDataSource dataSource() {
        DruidDataSource datasource = new DruidDataSource();
        datasource.setUrl(dataConfig.getUrl());
        datasource.setUsername(dataConfig.getUsername());
        datasource.setPassword(dataConfig.getPassword());
        datasource.setDriverClassName(dataConfig.getDriverClassName());
        return datasource;
    }

}
